package com.atguigu.srb.serviceoss.controller;


import com.atguigu.srb.serviceoss.service.OssService;
import com.atguigu.srb.base.result.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/oss/")
@Api(tags = "文件操作")
public class OssController {

    @Resource
    OssService ossService;

    @PostMapping("upload")
    @ApiOperation("文件上传")
    //第二个参数是上传文件保存到oss桶中的哪个目录下
    public ResponseVo upload(MultipartFile file, @RequestParam("module")String module){
         String path =  ossService.upload(file,module);
         return ResponseVo.ok().data("path",path);
    }


    @DeleteMapping("delete")
    @ApiOperation("文件删除")
    public ResponseVo delete(@RequestParam("path") String path){
        ossService.delete(path);
        return ResponseVo.ok().message("文件删除成功");
    }
}
